package com.example.a28796.beautiful;

import android.content.Intent;
import android.graphics.Color;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.a28796.beautiful.styAdapter.ShequPagerAdapter;
import com.example.a28796.beautiful.styfragment.FragmentHot;
import com.example.a28796.beautiful.styfragment.FragmentNew;
import com.example.a28796.beautiful.styfragment.FragmentNice;
import com.example.a28796.beautiful.stytools.CubeTransformer;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;


public class QuanziTwoActivity extends AppCompatActivity {
    private ViewPager mViewPager;
    private TabLayout mTabLayout;
    private PagerAdapter mPagerAdapter;
    private ImageView ivIcon;
    private TextView tvName,tvCount;
    private List<String> titles;
    private List<Fragment> mFragments;
    private CollapsingToolbarLayout mLayout;
    private Toolbar toolbar;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_quanzi_two);
        initView();
        initData();
        setData();
    }

    private void setData() {
        mViewPager.setAdapter(mPagerAdapter);
        mViewPager.setPageTransformer(true,new CubeTransformer());
        mTabLayout.setupWithViewPager(mViewPager);
    }

    private void initData() {
        Intent intent = getIntent();
        String url = intent.getStringExtra("url");
        String name = intent.getStringExtra("name");
        int count = intent.getIntExtra("count",100);
        Picasso.with(this).load(url).into(ivIcon);
        tvName.setText(name);
        tvCount.setText(count+"篇");

        mLayout.setTitle(name);
        toolbar.setTitle(name);

        mFragments = new ArrayList<>();
        titles = new ArrayList<>();
        titles.add("热门");
        titles.add("精华");
        titles.add("最新");
        for (int i = 0; i < titles.size(); i++) {
            if (i == 0) {
                mFragments.add(new FragmentHot());
            } else if (i == 1) {
                mFragments.add(new FragmentNice());
            } else if (i == 2) {
                mFragments.add(new FragmentNew());
            }
        }
        mPagerAdapter = new ShequPagerAdapter(getSupportFragmentManager(), mFragments, titles);

    }

    private void initView() {


        mLayout = (CollapsingToolbarLayout) findViewById(R.id.cl_quanzi_test);
        mTabLayout = (TabLayout) findViewById(R.id.tbl_quanzi_show);
        mViewPager = (ViewPager) findViewById(R.id.vp_quanzi_show);
        mViewPager = (ViewPager) findViewById(R.id.vp_quanzi_show);
        ivIcon = (ImageView) findViewById(R.id.iv_quanzi_icon);
        tvName = (TextView) findViewById(R.id.tv_quanzi_title);
        tvCount = (TextView) findViewById(R.id.tv_quanzi_count);
        toolbar = (Toolbar) findViewById(R.id.tb_quanzi_toolbartwo);
        if(toolbar !=null){
            setSupportActionBar(toolbar);
        }

        mLayout.setExpandedTitleColor(Color.BLACK);
        mLayout.setContentScrimResource(R.mipmap.common_background);
    }

}
